package com.chen.blue.converter.system;

import com.chen.blue.domain.dto.system.UserDto;
import com.chen.blue.domain.dto.system.UserRoleDto;
import com.chen.blue.domain.dto.system.update.UserRoleDtoEdit;
import com.chen.blue.domain.model.system.UserRoleModel;
import com.chen.blue.domain.model.system.UsersModel;
import com.chen.blue.domain.vo.system.UserVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/4/28.
 */
@SuppressWarnings("all")
public abstract class UserRoleConverter {

    private static final BeanCopier dtoToModel = BeanCopier.create(UserRoleDto.class, UserRoleModel.class, false);
    private static final BeanCopier dtoEditToModel = BeanCopier.create(UserRoleDtoEdit.class, UserRoleModel.class, false);


    /**
     * dto->model
     *
     * @param userDto
     * @return
     */
    public static UserRoleModel dtoToModel(UserRoleDto userRoleDto) {

        if (Objects.isNull(userRoleDto)) {
            return null;
        }

        UserRoleModel userRoleModel = new UserRoleModel();
        dtoToModel.copy(userRoleDto, userRoleModel, null);
        return userRoleModel;

    }

    /**
     * dtoList->modelList
     *
     * @param userRoleDtoList
     * @return
     */
    public static List<UserRoleModel> dtoListToModelList(List<UserRoleDto> userRoleDtoList) {

        if (userRoleDtoList.size() == 0) {
            return null;
        }

        List<UserRoleModel> userRoleModelList = new ArrayList<>();
        for (UserRoleDto userRoleDto : userRoleDtoList) {
            userRoleModelList.add(dtoToModel(userRoleDto));
        }

        return userRoleModelList;

    }

    /**
     * editDto->model
     *
     * @param userDtoEdit
     * @return
     */
    public static UserRoleModel dtoEditToModel(UserRoleDtoEdit userRoleDtoEdit) {

        if (Objects.isNull(userRoleDtoEdit)) {
            return null;
        }

        UserRoleModel userRoleModel = new UserRoleModel();
        dtoEditToModel.copy(userRoleDtoEdit, userRoleModel, null);
        return userRoleModel;

    }

    /**
     * editDtoList->modelList
     *
     * @param userRoleDtoList
     * @return
     */
    public static List<UserRoleModel> editDtoListToModelList(List<UserRoleDtoEdit> userRoleDtoEditList) {

        if (userRoleDtoEditList.size() == 0) {
            return null;
        }

        List<UserRoleModel> userRoleModelList = new ArrayList<>();
        for (UserRoleDtoEdit userRoleDtoEdit : userRoleDtoEditList) {
            userRoleModelList.add(dtoEditToModel(userRoleDtoEdit));
        }

        return userRoleModelList;

    }

}
